package com.es.core.controller;

import com.es.system.domain.SysOperateLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 描述:
 * Old-AgeCareSystem-
 *
 * @author Derek
 * @create 2021-12-07 11:14
 */
@RestController
@RequestMapping("/redis")
@Slf4j
public class RedisController {

    @Autowired
    private RedisTemplate redisTemplate;

    @PostMapping("/save")
    public String save(String str){
        ValueOperations<Object,Object> vo = redisTemplate.opsForValue();
        vo.set("a:b","es-redis-springboot-"+str);
        return str;
    }

    @GetMapping("/read")
    public Object read(){
        //
        //String key = "oacs:system:logs";
        String key = "oacs:system:logs-timeout";
        List<SysOperateLog> list = (List<SysOperateLog>) redisTemplate.opsForValue().get(key);
        log.info("list.size={}",list.size());
        return list;
    }
}
